﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Baza.EF.BLL;
using Baza.EF.DAL;


namespace Pep_3014_3070_Desktop
{
    public partial class ChangeDataApartment : Form
    {
        public ChangeDataApartment()
        {
            InitializeComponent();
        }



        private void ChangeDataApartments_Load(object sender, EventArgs e)
        {
            cmbIzanajmljivac.DataSource = DAIznajmljivaciApartmani.SelectOwners();
            cmbIzanajmljivac.DisplayMember = "FirstName,LastName";
        }

        private void cmbIzanajmljivac_Format(object sender, ListControlConvertEventArgs e)
        {
            string lastname = ((Owners)e.ListItem).FirstName;
            string firstname = ((Owners)e.ListItem).LastName;
            e.Value = lastname + " " + firstname;
        }

        private void cmbIzanajmljivac_SelectedIndexChanged(object sender, EventArgs e)
        {

            cmbApartman.DisplayMember = "";
            Owners owner = (Owners)cmbIzanajmljivac.SelectedItem;

            cmbApartman.DataSource = DAIznajmljivaciApartmani.SelectApartmentBYOwner(owner);
            cmbApartman.DisplayMember = "Title";





        }

        private void btnOdustani_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmbApartman_SelectedIndexChanged(object sender, EventArgs e)
        {
            Apartments apartment = (Apartments)cmbApartman.SelectedItem;

            if (apartment != null)
            {
                //Address addres = DAIznajmljivaci_Apartmani.SelectAddresBYAddresID(apartment.AdresID).First();
                // ApartmentType type = DAIznajmljivaci_Apartmani.SelectApartmentTypeByID(apartment.ApartmentTypeID);

                NazivApartmanaInput.Text = apartment.Title;

                //kreirati proceduru
                // cmbTipApartmana.DataSource = apartment.ApartmentType.Name;

                cmbGrad.DataSource = DAIznajmljivaciApartmani.SelectCities();
                cmbGrad.DisplayMember = "Name";
                //   cmbGrad.SelectedIndex = (int)apartment.Address.CityID;

                BrojUliceInput.Text = apartment.Address.StreetNumber.ToString();
                BrojApartmanaInput.Text = apartment.Address.ApartmentNumber.ToString();
                Adresa1Input.Text = apartment.Address.Address1;
                Adresa2Input.Text = apartment.Address.Address2;




                maxBrGostijuInput.Text = apartment.MaxGuests.ToString();
                maxBrOdraslihInput.Text = apartment.MaxAdults.ToString();
                MaxBrDjeceInput.Text = apartment.MaxChildren.ToString();
                MaxBrBebaInput.Text = apartment.MaxBabies.ToString();

                MinDaniOstankaInput.Text = apartment.MinStay.ToString();
                MaxDaniOstankainput.Text = apartment.MaxStay.ToString();

                SpratInput.Text = apartment.Floor.ToString();

                if (apartment.Elevator == true)
                    checkBoxLift.Checked = true;
                else
                    checkBoxLift.Checked = false;


                BrojSobaInput.Text = apartment.Beds.ToString().ToString();
                BrojToaletaInput.Text = apartment.Toilets.ToString();
                BrojKupatilaInput.Text = apartment.Bathrooms.ToString();



            }
            else
            {
                NazivApartmanaInput.Text = "";
                BrojSobaInput.Text = "";
                BrojToaletaInput.Text = "";
                BrojKupatilaInput.Text = "";

            }
        }

        private void btnSpremi_Click(object sender, EventArgs e)
        {

        }
    }
}
